
/* PROCESSOR SPECIFICS */
//#define FCY  70000000	 // xtal = 8Mhz; with PLL -> 70 MIPS
#define FPWM 20000		 // 20 kHz, so that no audible noise is present.

#define CW	0		// Counter Clock Wise direction
#define CCW	1		// Clock Wise direction
#define SWITCH_S2	  !GPIO_ReadDataBit(GPIO0, GPIO_Pin_1)  // Run button
#define SWITCH_UP	  !GPIO_ReadDataBit(GPIO2, GPIO_Pin_1)   // Direction button

#define HALLA_BIT   (GPIO_ReadDataBit(GPIO0, GPIO_Pin_4))  // HALLA
#define HALLB_BIT   (GPIO_ReadDataBit(GPIO0, GPIO_Pin_5))  // HALLB
#define HALLC_BIT   (GPIO_ReadDataBit(GPIO0, GPIO_Pin_6))  // HALLC

/* ALGORITHM SPECIFICS */
#define NO_POLEPAIRS 4

// In the sinewave generation algorithm we need an offset to be added to the
// pointer when energizing the motor
#define PHASE_OFFSET_CW 49152
#define PHASE_OFFSET_CCW 49152

// Period Calculation
#define MINPERIOD	600     // For 20000 max erpm
#define MAXPERIOD	60000   // For 200 min erpm

#define _50MILLISEC 50      // Used as a timeout with no hall effect sensors
                            // transitions and Forcing steps according to the
                            // actual position of the motor
#define _1SEC 1000          // after this time has elapsed, the motor is
                            // consider stalled and it's stopped

#define PERIOD_FILTER_CONST 32
#define POT_FILTER_CONST    64

/* for calculation for PHASE_INC */
#define PHASE_INC_CALC 655360UL

/* for speed rpm calculation */
#define SPEED_RPM_CALC (12000000UL / NO_POLEPAIRS)

#define MIN_SPEED 300

#define PDC1 MCPWM->MAT0
#define PDC2 MCPWM->MAT1
#define PDC3 MCPWM->MAT2

#define CCR_VALUE_100US 1200
#define CCR_VALUE_1MS 12000
